package com.eastedu.superise.handler.basic;

import com.eastedu.manager.BasicResourceManager;
import com.eastedu.repository.basic.po.BasicResourcePO;
import com.eastedu.superise.handler.AbstractHistoricalDataHandler;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.sql.SQLException;

/**
 * 更新应用者
 * @author zhangzhishuai
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class BasicApplyUserIdHistoricalDataHandler extends AbstractHistoricalDataHandler<BasicResourcePO> {

    private final BasicResourceManager basicResourceManager;


    @Override
    protected String getSql() {
        return "SELECT * FROM t_basic_resource WHERE create_userid = 1343665 " +
                "UNION " +
                "SELECT * FROM t_basic_resource WHERE JSON_CONTAINS(sources_json, JSON_OBJECT('provider', 1343665))";
    }

    @Override
    public void callback(BasicResourcePO po) throws SQLException {
        int newApplyUserId = 1343655;
        int existedApplyUserId = 1343665;
        basicResourceManager.updateApplyUserId(po, newApplyUserId, null, existedApplyUserId);
    }

}
